package com.me.study.concurrent.threadPool;

import com.me.common.util.SleepUtil;

/**
 * 线程 join() 测试类: 子线程报错后，主线程的运行状况<p>
 *  join() 依赖其他线程执行的结果，但是子线程异常了主线程也会继续执行！！！
 *
 * @author ME
 * @date   2019/6/4
 */
public class TestThreadJoin {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            SleepUtil.seconds(3);
            throw new RuntimeException("2333");
        }, "Join-Thread1");
        Thread t2 = new Thread(() -> {
            SleepUtil.seconds(5);
        }, "Join-Thread2");
        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("完成任务~~~");
    }
}
